<template>
  <div class="demo-form-inline">
    <template>
      <el-table border :data="[tableData]" style="width: 100%">
        <el-table-column prop="name" label="名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column prop="desc" label="介绍名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.desc }}
          </template>
        </el-table-column>
        <el-table-column prop="tag" label="标签" align="center">
          <template slot-scope="scope">
            {{ scope.row.tag }}
          </template>
        </el-table-column>
        <el-table-column prop="type" label="优惠券类型" align="center">
          <template slot-scope="scope">
            {{ convertStatus2(scope.row.type) }}
          </template>
        </el-table-column>
        <el-table-column prop="min" label="最低消费" align="center">
          <template slot-scope="scope">
            {{ "满" + scope.row.min + "元可用" }}
          </template>
        </el-table-column>
        <el-table-column prop="discount" label="优惠面值" align="center">
          <template slot-scope="scope">
            {{ "减免" + scope.row.discount + "元" }}
          </template>
        </el-table-column>
      </el-table>
      <el-table border :data="[tableData]" style="width: 100%">
        <el-table-column prop="limit" label="每人限额" align="center">
        </el-table-column>
        <el-table-column prop="status" label="当前状态" align="center">
          <template slot-scope="scope">
            {{ convertStatus3(scope.row.status) }}
          </template>
        </el-table-column>
        <el-table-column prop="goodsType" label="商品范围" align="center">
          <template slot-scope="scope">
            {{ convertStatus1(scope.row.goodsType) }}
          </template>
        </el-table-column>
        <el-table-column prop="aaa" label="有效期" align="center">
          <template slot-scope="scope">
            {{ "自" + scope.row.startTime + "至" + scope.row.updateTime }}
          </template>
        </el-table-column>
        <el-table-column label="优惠兑换码" align="center"> </el-table-column>
        <el-table-column prop="total" label="发行数量" align="center">
        </el-table-column> </el-table
    ></template>
    <div class="sou">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item>
          <el-input
            v-model="formInline.userId"
            placeholder="请输入用户ID"
            size="mini"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="formInline.status"
            size="mini"
            placeholder="请选择使用状态"
          >
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option> </el-select
        ></el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="onSubmit"
            size="mini"
            icon="el-icon-search"
            >查找</el-button
          >
        </el-form-item>
      </el-form>
      <el-table border :data="info" style="width: 100%">
        <el-table-column prop="id" label="用户优惠券ID" align="center">
        </el-table-column>
        <el-table-column prop="userId" label="用户ID" align="center">
        </el-table-column>
        <el-table-column prop="startTime" label="领取时间" align="center">
        </el-table-column>
        <el-table-column prop="status" label="使用状态" align="center">
          <template slot-scope="scope">
            {{ convertStatus4(scope.row.status) }}
          </template>
        </el-table-column>
        <el-table-column prop="tag" label="订单ID" align="center">
        </el-table-column>
        <el-table-column prop="tag" label="使用时间" align="center">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { idfind, redact, del, add, search } from "@/api/promotion";
export default {
  data() {
    return {
      tableData: {
        id: "",
        name: "",
        desc: "",
        tag: "",
        min: "",
        discount: "",
        limit: "",
        goodsType: "",
        type: "",
        status: "",
        startTime: "",
        updateTime: "",
        total: "",
      },
      get: {
        page: 1,
        limit: 20,
        couponId: "",
        sort: "add_time",
        order: "desc",
      },
      formInline: {},
      info: {},
      total: 0,
      options1: [
        {
          value: 0,
          label: "未使用",
        },
        {
          value: 1,
          label: "已使用",
        },
        {
          value: 2,
          label: "已过期",
        },
        {
          value: 3,
          label: "已下架",
        },
      ],
    };
  },
  created() {
    this.tableData = {
      id: this.$route.query.id,
      name: this.$route.query.name,
      desc: this.$route.query.desc,
      tag: this.$route.query.tag,
      min: this.$route.query.min,
      discount: this.$route.query.discount,
      limit: this.$route.query.limit,
      goodsType: this.$route.query.goodsType,
      type: this.$route.query.type,
      status: this.$route.query.status,
      startTime: this.$route.query.startTime,
      updateTime: this.$route.query.updateTime,
      status: this.$route.query.status,
      total: this.$route.query.total,
    };
    this.run();
  },
  methods: {
    //数据获取
    run() {
      this.get.couponId = this.tableData.id
      idfind(this.get).then((res) => {
        console.log(res);
        if ((res.data.errmsg = "成功")) {
          this.info = res.data.list;
          this.total = res.data.total;
          console.log(this.tableData);
        }
      });
    },
    //查找
    onSubmit() {
      this.get.page = 1;
      this.get.userId = this.formInline.userId;
      this.get.status = this.formInline.status;
      this.run();
    },
    convertStatus1(unitstatus) {
      if (unitstatus === 0) {
        return "全场通用";
      } else if (unitstatus === 1) {
        return "指定分类";
      }
      return "指定商品";
    },
    convertStatus2(unitstatus) {
      if (unitstatus === 0) {
        return "通用领券";
      } else if (unitstatus === 1) {
        return "注册赠券";
      }
      return "兑换码";
    },
    convertStatus3(unitstatus) {
      if (unitstatus === 0) {
        return "正常";
      } else if (unitstatus === 1) {
        return "已过期";
      }
      return "已下架";
    },
    convertStatus4(unitstatus) {
      if (unitstatus === 0) {
        return "未使用";
      } else if (unitstatus === 1) {
        return "已使用";
      }else if (unitstatus === 2) {
        return "已过期";
      }
      return "已下架";
    },
  },
};
</script>

<style></style>
